package com.lagou.stage6module1.consumer;

import com.lagou.stage6module1.domain.Order;
import com.lagou.stage6module1.mapper.OrderMapper;
import com.lagou.stage6module1.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderDelayConsumer {
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderMapper orderMapper;

    @RabbitListener(queues = "order.queue.dlx")
    public void handlerDelayOrder(String message){
        Order order = orderMapper.findByOrderId(message);
        if (order.getPay()){
            System.out.println(message + ": 已经支付");
            return;
        }
        order.setStatus(false);
        orderMapper.updateById(order);
        System.out.println("消息队列超过支付时限的消息：" + message);
    }
}
